package top.huhuiyu.teachproject.service.impl;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import top.huhuiyu.teachproject.base.BaseResult;
import top.huhuiyu.teachproject.dao.TbMessageDAO;
import top.huhuiyu.teachproject.entity.AuthInfo;
import top.huhuiyu.teachproject.entity.message.TbMessage;
import top.huhuiyu.teachproject.service.TbMessageService;
import top.huhuiyu.teachproject.utils.AuthInfoUtils;

@Service
@RequiredArgsConstructor
public class TbMessageServiceImpl implements TbMessageService {
  private final TbMessageDAO tbMessageDAO;

  @Override
  public BaseResult add(TbMessage tbMessage) {
    AuthInfo authInfo = AuthInfoUtils.authInfo();
    tbMessage.setUid(authInfo.getUserId());
    int i = tbMessageDAO.insert(tbMessage);
    return i == 1 ? BaseResult.ok("添加成功") : BaseResult.fail("添加失败");
  }

}
